﻿#include "CTPTradeLib.h"
#include "Tools.h"
#include "CTPTime.h"
#include "SymbolDetail.h"

// 负责CTP合约的下载
int main(int argc, char* argv[])
{
	// 检查是否已经获取了今日合约
	time_t tmStamp = Tools::GetCurrentTimeStamp();
	// 获得行情段所属的交易日
	tm curTm = Tools::GetDateTimeFrmStamp(tmStamp);
	tm marketDay = CTPTm::GetMarketDay(curTm);
	time_t marketStamp = Tools::GetTimeStamp(marketDay);
	SymbolPackage::SymbolsReader symbolManager(marketStamp);
	std::list<SymbolPackage::SymbolInfo> pSymbolList;
	symbolManager.GetAllFutureList(pSymbolList);
	if (!pSymbolList.empty())
	{
		return 88;
	}
	// 假期或周末直接返回
	CTPTm::HolidayManager pManager;
	if (!pManager.IsMarketDay(tmStamp))
	{
		return 88;
	}

	CTPTradeLib orderOperator;
	orderOperator.Init();

	// 查询合约之前，要遍历所有的期货合约，记录一下下单合约
	//std::list<SymbolPackage::SymbolInfo> allSymbolInfoList;
	//SymbolPackage::GetTheLastFutureSymbolInfoList(allSymbolInfoList);
	//WaveTurnRoundStrategy circler;
	//OrderSymbolReaderWriter orderSymbols;
	//for (std::list<SymbolInfo>::iterator it = allSymbolInfoList.begin(); it != allSymbolInfoList.end(); ++it)
	//{
	//	if (circler.CheckOrder(it->InstrumentID))
	//	{
	//		orderSymbols.AppendSymbol(it->InstrumentID);
	//	}
	//}
	//orderSymbols.Save();
	orderOperator.QueryContracts();

	orderOperator.Logout();
	return 0;
}